package com.test.testCode.test;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.stream.Collectors;

public class List2Map {

    public static void main(String[] args) {
        List<Person> list = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Person p = new Person();
            p.setName("name" + i);
            p.setAge(String.valueOf(10 + i));
            list.add(p);
        }

        Map<String,String> map1 = list.parallelStream().collect(Collectors.toMap(Person::getName,Person::getAge));
        for (Map.Entry<String,String> entry : map1.entrySet()){
            System.out.println(entry.getKey() +"  "+ entry.getValue());
        }
        System.out.println("====================================");
        List<Map<String,String>> map = new ArrayList<>();
        List<String> list1  = list.parallelStream().collect(Collectors.toMap(Person::getName,Person::getAge)).values().parallelStream().collect(Collectors.toList());
        list1.parallelStream().forEach(tt ->{
            System.out.println(tt);
        });
        System.out.println("====================================");
        map1.forEach((k,v) ->
            System.out.println("key : " + k + "; value : " + v)
        );

        System.out.println("=======================111111=============");
        map1.put("kkkk","kkkkk10");
        map1.compute("name9",new BiFunction<String, String, String>() {
            @Override
            public String apply(String t, String u) {
                System.out.println("t值=" + t);
                System.out.println("u值=" + u);
                return t + "_" + u;
            }
        });
        map1.forEach((k,v) ->System.out.println("key : " + k + "; value : " + v));

        System.out.println("+++++++++++++++++++++++++");
        map1.compute("name4", (k, v) -> "2222222");
        map1.forEach((k,v) ->System.out.println("key : " + k + "; value : " + v));
    }


}

class Person {
    private String name;
    private String age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }
}
